<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Main extends Mycontroller {

    public $template = "basic";
    
    public function before() {
        parent::before();
        
        $auth = Auth::instance();
     // $this->user = $this->auth->get_user();
     
        if(!$auth -> logged_in()){
            Controller::redirect('auth');    
        }
    } 
    
    public function action_index() {
        $data = array();
        $auth = Auth::instance();
        
        $data['logged_in'] = false;
        if($auth -> logged_in()) {
            $data['logged_in'] = true;     
            
            $List = new Model_Item_List();
            $array = $List -> get_list();
            $data['list'] = $array;
        }
        else {
            Controller::redirect('auth'); 
        }
        
        //echo Debug::dump($data);
        
        $this -> template -> content = View::factory('home', $data);
    }
    
    public function action_group() {
        $data = array();
        $auth = Auth::instance();
        
        $data['logged_in'] = false;
        if($auth -> logged_in()) {
            $data['logged_in'] = true;     
            
            $Groups = new Model_Item_Groups();
            $groups = $Groups -> gel_list_groups();
            $data['groups'] = $groups;
        }
        else {
            Controller::redirect('auth'); 
        }
        
        $this -> template -> content = View::factory('groups', $data);    
    }
    
    public function action_users() 
    {
        /*
        $users = ORM::factory('Registration_Husers')
               -> join('roles', 'RIGHT OUTER')
               -> on('user.role_id', '=', 'roles.id')
               -> select('roles.*')
               -> find_all();
        */
        
        $users = new Model_Registration_Huser();
        $users -> join('roles', 'RIGHT OUTER') -> on('user.role_id', '=', 'roles.id') -> select('roles.*') -> find_all();     
        foreach($users as $user)
        {
            echo 'имя = ' . $user->name . ' роль ='. $user->role_name . '<br />';
        }
    }

} 
